package com.wd.tech.activity.base;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;

import butterknife.ButterKnife;


/**
 * @author 时文豪
 * @description:
 * @date :2020/7/2 12:04
 */
public abstract class BaseFragment<P extends BasePreantert>extends Fragment implements IBaseView {
   P mPreantert;
    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View inflate = View.inflate(getContext(), getLayoutId(), null);
        mPreantert=initPreantert();
        ButterKnife.bind(this,inflate);
        initView(inflate);
        initData();
        return inflate;
    }

    protected abstract int getLayoutId();

    protected abstract P initPreantert();

    protected abstract void initView(View inflate);

    protected abstract void initData();

    public P getmPreantert(){
        if(mPreantert!=null){
            return mPreantert;
        }
        return null;
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
        if(mPreantert!=null){
            mPreantert.datachView();
            mPreantert=null;
        }
    }






}
